package com.lujianfei.redpacketstat.utils

import android.util.Log

class ClickHelper {

        private var lastTime = 0L
        private var clickCounts = 0

        fun clickTimes(maxFastClickTime:Int, duration:Int, callback:()->Unit) {
            if (lastTime.equals(0)) {
                lastTime = System.currentTimeMillis()
                clickCounts = 0
            } else {
                if (System.currentTimeMillis() - lastTime < duration) { // 计算两次单击的时间差
                    ++clickCounts
                    if (clickCounts == maxFastClickTime - 1) {
                        callback()
                        clickCounts = 0
                    }
                } else {
                    clickCounts = 0
                }
                lastTime = System.currentTimeMillis()
            }
        }
}